
// 会话 ID 同步与 postMessage 通知: 抽成
import { useEffect } from "react";
import { StreamConfigurations } from "../pc";

interface UseSessionIdPostMessageProps {
    activeStreamId: string;
    sessionIds: Map<string, number>;
    onSessionIdChange: (id: number) => void;
}

export default function useSessionIdPostMessage({
    activeStreamId,
    sessionIds,
    onSessionIdChange,
}: UseSessionIdPostMessageProps) {
    useEffect(() => {
        const currentSessionId = sessionIds.get(activeStreamId);
        if (currentSessionId !== undefined) {
            onSessionIdChange(currentSessionId);
            const parentWindow = window.parent;
            parentWindow.postMessage(
                { type: "id", value: StreamConfigurations },
                "*"
            );
        }
    }, [activeStreamId, sessionIds, onSessionIdChange]);
} 